package com.doctcloud.datacloud.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.doctcloud.common.core.annotation.Excel;
import com.doctcloud.common.core.annotation.NotZero;
import lombok.*;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;

import static com.doctcloud.common.core.utils.StringUtils.trim;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@EqualsAndHashCode(of = {"patientId","visitId","orderNo","orderSubNo","itemNo"})
@TableName("orders_costs")
public class OrdersCostsEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    @Excel(name = "患者ID")
    @NotBlank(message = "患者ID不得为空")
    private String patientId;
    @Excel(name = "住院标识")
    @NotZero(message = "住院标识不得为零或NULL")
    private Integer visitId;
    @Excel(name = "医嘱号")
    @NotZero(message = "医嘱号不得为零或NULL")
    private Integer orderNo;
    @Excel(name = "医嘱子序号")
    @NotZero(message = "医嘱子序号不得为零或NULL")
    private Integer orderSubNo;
    @Excel(name = "序号")
    @NotZero(message = "序号不得为零或NULL")
    private Integer itemNo;
    @Excel(name = "项目类别")
    @NotBlank(message = "项目类别不得为空")
    private String itemClass;
    @Excel(name = "项目名称")
    private String itemName;
    @Excel(name = "项目代码")
    @NotBlank(message = "项目代码不得为空")
    private String itemCode;
    @Excel(name = "项目规格")
    @NotBlank(message = "项目规格不得为空")
    private String itemSpec;
    @Excel(name = "单位")
    private String units;
    @Excel(name = "数量")
    @NotZero(message = "数量不得为空或为零")
    private Integer amount;
    @Excel(name = "总量")
    @NotZero(message = "数量不得为空或为零")
    private Integer totalAmount;
    @Excel(name = "计价金额")
    private Double costs;

    public void setItemClass(String itemClass) {
        this.itemClass = trim(itemClass);
    }

    public void setItemName(String itemName) {
        this.itemName = trim(itemName);
    }

    public void setItemCode(String itemCode) {
        this.itemCode = trim(itemCode);
    }

    public void setItemSpec(String itemSpec) {
        this.itemSpec = trim(itemSpec);
    }

    public void setTotalAmount(Integer totalAmount) {
        this.totalAmount = totalAmount != null ? totalAmount : 0;
    }

    public void setCosts(Double costs) {
        this.costs = costs != null ? costs : 0.0;
    }

    @Data
    public static class Key {
        private final String patientId;
        private final Integer visitId;
        private final Integer orderNo;
        private final Integer orderSubNo;
        private final Integer itemNo;

        public Key(String patientId, Integer visitId, Integer orderNo, Integer orderSubNo,Integer itemNo) {
            this.patientId = patientId;
            this.visitId = visitId;
            this.itemNo = itemNo;
            this.orderNo = orderNo;
            this.orderSubNo = orderSubNo;
        }
    }

}
